<template>
  <div class="tabs">
    <tabs :defaultActiveKey="defaultActiveKey" @callback="setAActiveKey">
      <tab
        :label="title[index].title"
        :index="String(index+1)"
        v-for="(item,index) in djsData"
        :key="index"
      >
        <div class="panel hotsongs on">
          <ul class="list">
            <!-- 这里还要进行一次for循环，因为后台的数据嵌套了两次 -->
            <li class="song url" v-for="(dj,index) in item.djRadios" :key="index">
              <div class="poster">
                <!-- 图片 -->
                <img :src="dj.picUrl" alt />
              </div>
              <!-- 内容 -->
              <div class="info">
                <div class="name">{{dj.desc}}</div>
                <div class="author">{{dj.name}}</div>
              </div>
            </li>
          </ul>
          <router-link
          tag="div"
          :to="{name:'djmore',params:{id:title[index].id}}"
          class="more-songs"
          >
          加载更多
          </router-link>

        </div>
      </tab>
    </tabs>
  </div>
</template>

<script>
import axios from '../../utils/request'
export default {
  data () {
    return {
      defaultActiveKey: '1',
      djsData: [],
      // ['情感故事', '情感调频', '影视娱乐']
      title: [
        {
          id: 2,
          title: '情感故事'
        },
        {
          id: 3,
          title: '情感调频'
        },
        {
          id: 6,
          title: '影视娱乐'
        }
      ]
    }
  },
  mounted () {
    // this.$api.getreCommend({
    //   type: 2
    // }).then(res => {
    //   console.log(res)
    // })
    // 网络合并同时拿到三条数据
    const that = this
    function getDJ2 () {
      return that.$api.getreCommend({ type: 2 })
    }
    function getDJ4 () {
      return that.$api.getreCommend({ type: 3 })
    }
    function getDJ6 () {
      return that.$api.getreCommend({ type: 6 })
    }
    axios.all([getDJ2(), getDJ4(), getDJ6()]).then(
      axios.spread((dj2, dj3, dj5) => {
        this.djsData.push(dj2, dj3, dj5)
        console.log(dj2, dj3, dj5)
      })
    )
  },
  methods: {
    setAActiveKey (index) {
      this.defaultActiveKey = index
    }
  }
}
</script>

<style scoped>
.tabs {
  padding: 10px;
  background: #fff;
}
.musictop {
  background: #fff;
  padding: 10px;
}

.panel {
  border-top: 1px solid #eee;
  position: relative;
  top: -1px;
  display: block;
  background: #fff;
}

.list {
  padding-top: 0;
  height: 450px;
}

.panel .list li {
  height: 75px;
  border-bottom: 1px solid #eee;
  padding-left: 0;
  display: flex;
  padding-top: 10px;
  line-height: 75px;
}

.panel .list li .poster {
  position: relative;
  width: 45px;
  margin-right: 8px;
}

.panel .list li .poster img {
  border: 1px solid #eee;
}
.info {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.info .name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 16px;
  color: #333;
}

.info .author {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  color: #999;
  margin-top: 2px;
}

.more-songs {
  color: #999;
  margin-top: 9px;
  font-size: 12px;
  text-align: center;
  height: 32px;
  line-height: 32px;
}
</style>
